const { createBot, createProvider, createFlow, addKeyword, MemoryDB } = require('@builderbot/bot')
const { BaileysProvider } = require('@builderbot/bot')

/** send static messages */
const welcomeFlow = addKeyword(['hello', 'hi']).addAnswer('Ey! welcome')

/** send dynamic message from db or other sources */
const infoFlow = addKeyword('info')
    .addAction(async (ctx, { flowDynamic }) => {
        await flowDynamic(`Welcome ${ctx.name}`)
    })

/** send media files */
const mediaFlow = addKeyword('image')
    .addAnswer(`Send Image A`, { media: 'https://i.imgur.com/AsvWfUX.png' })
    .addAction(async (ctx, { flowDynamic }) => {
        await flowDynamic(`Welcome ${ctx.name}`)
        await flowDynamic(
            [
                {
                    body: 'Send Image B',
                    media: 'https://i.imgur.com/w0RtKnN.png'
                }
            ]
        )
    })

/** initialization bot */
const main = async () => {

    const adapterDB = new MemoryDB()
    const adapterFlow = createFlow([welcomeFlow, infoFlow])
    const adapterProvider = createProvider(BaileysProvider)

    adapterProvider.initHttpServer(3000)

    await createBot({
        flow: adapterFlow,
        provider: adapterProvider,
        database: adapterDB,
    })
}

main()

